﻿
var connection = require("../../app_modules/dbAccess/mongoConfig.js");

var mongoose = require('mongoose');
mongoose.Promise = global.Promise;
var db = mongoose.createConnection(connection.getConnectionString(""));

//创建模型【骨架模板】
var Schema = mongoose.Schema; 
var userSchema = new Schema({
    code: String,
    name: String,
    mail: String,
    telephone: String,
    phone: String,
    address: String,
    remark: String,
    companyCode: String,
    companyName: String,
    status:String,
    password:String,
    createDate: Date,
    token:String,
    icon:String,
    metadata:Schema.Types.Mixed
});

userSchema.methods.add = function (user, callback) {
    this.code = user.code;
    this.name = user.name;
    this.mail = user.mail;
    this.telephone = user.telephone;
    this.phone = user.phone;
    this.address = user.address;
    this.remark=user.remark;
    this.companyCode=user.companyCode;
    this.companyName=user.companyName;
    this.status=user.status;
    this.password=user.password;
    this.createDate=user.createDate;
    this.token=user.token;
    this.icon=user.icon;
    this.metadata=user.metadata;
    this.save(callback);
}


var user = db.model('user', userSchema);
module.exports = user;
